-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Follow up PR: #28097 Simplify branch statement #29243
Conversation
|
||
if len(level_index): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not what i meant
can u eliminate this branch here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I eliminate branch. But I don't know how not to use branch and not conflict with test cases together. Could you give me a clue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback i think the blocker here is clarifying for this contributor what you're asking for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think CI logs are around but do we know why this change fails CI? I think @jreback point is that this seems unnecessary so unclear why it is causing the failures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WillAyd
Because "Index.take"
if allow_fill and fill_value is not None:
msg = "Unable to fill values because {0} cannot contain NA"
raise ValueError(msg.format(self.__class__.__name__))
cause fail.
Some Indexes use ".take" from "Index.take". If grouper = level_index.take(codes, fill_value=True)
all the time and "level_index" use "take" from "Index.take", then raise exception.
So I changed check "level_index" empty or not. this check avoids from exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm OK. I guess that goes back to this line:
pandas/pandas/core/indexes/base.py
Line 804 in 2470690
f"Unable to fill values because {cls_name} cannot contain NA" |
So I guess we would have to allow fill_value
being passed to Index types that can't hold NA for this to work.
I think I'd be OK with that but any objections @jreback?
>>> pd.Index(range(5)).take([3], fill_value=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 901, in take
raise ValueError(msg.format(self.__class__.__name__))
ValueError: Unable to fill values because RangeIndex cannot contain NA
>>> pd.Index(range(5)).astype(float).take([3], fill_value=1)
Float64Index([3.0], dtype='float64')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WillAyd
You are right. If Some level index in "MultiIndex", which can't hold NA do not pass flll_value
. can exist. So there is need to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proost I think you can replace the if
check to be if level_index._can_hold_na
: to at least be more explicit
e97d879
to
a212065
Compare
can you merge master and see if you can get passing |
|
||
if len(level_index): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proost I think you can replace the if
check to be if level_index._can_hold_na
: to at least be more explicit
bc71f05
to
29977dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the explicitness here is an improvement so lgtm. @jreback
thanks @proost this is not exactly what I was looking for, but its ok. thanks. |
…ndexing-1row-df * upstream/master: (194 commits) DOC Remove Python 2 specific comments from documentation (pandas-dev#31198) Follow up PR: pandas-dev#28097 Simplify branch statement (pandas-dev#29243) BUG: DatetimeIndex.snap incorrectly setting freq (pandas-dev#31188) Move DataFrame.info() to live with similar functions (pandas-dev#31317) ENH: accept a dictionary in plot colors (pandas-dev#31071) PERF: add shortcut to Timestamp constructor (pandas-dev#30676) CLN/MAINT: Clean and annotate stata reader and writers (pandas-dev#31072) REF: define _get_slice_axis in correct classes (pandas-dev#31304) BUG: DataFrame.floordiv(ser, axis=0) not matching column-wise bheavior (pandas-dev#31271) PERF: optimize is_scalar, is_iterator (pandas-dev#31294) BUG: Series rolling count ignores min_periods (pandas-dev#30923) xfail sparse warning; closes pandas-dev#31310 (pandas-dev#31311) REF: DatetimeIndex.get_value wrap DTI.get_loc (pandas-dev#31314) CLN: internals.managers (pandas-dev#31316) PERF: avoid copies if possible in fill_binop (pandas-dev#31300) Add test for multiindex json (pandas-dev#31307) BUG: passing TDA and wrong freq to TimedeltaIndex (pandas-dev#31268) BUG: inconsistency between PeriodIndex.get_value vs get_loc (pandas-dev#31172) CLN: remove _set_subtyp (pandas-dev#31301) CI: Updated version of macos image (pandas-dev#31292) ...
@meeseeksdev backport to 1.0.x |
… branch statement
…31689) Co-authored-by: proost <jwalag87@gmail.com>
xref #28097
This is follow up pr. eliminate branch statement. "grouper" variable is assigned when handle NAs.